<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-button type="primary" icon="el-icon-edit" @click="handleAddConsumer" style='position: absolute;right:100px;top:100px;'>添加入职</el-button>
            <div>
                <el-input v-model="query.eid" placeholder="员工编号" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                 <!-- <el-upload
                  style="display: inline-flex; position:absolute;right:100px;top:100px;margin-right:8px"
                  :show-file-list="false"
                  action="https://jsonplaceholder.typicode.com/posts/">
               <el-button @click =" exportData" type="success">
                 <i class="fa fa-level-up" aria-hidden="true" ></i>
                 导入数据
              </el-button>
              </el-upload> -->
            </div>
            <el-table
                :data="employeeData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="Eid" label="员工编号" width="55" align="center"></el-table-column>
				<el-table-column prop="Ename" label="姓名"></el-table-column>
                <el-table-column prop="Egender" label="性别"></el-table-column>
                <el-table-column prop="Eidcard" label="身份证号"></el-table-column>
				<el-table-column prop="Ephone" label="电话"></el-table-column>
                <el-table-column prop="Ebirth" label="出生日期"></el-table-column>
                <el-table-column prop="Edepartment" label="部门"></el-table-column>
                <el-table-column prop="Eposition" label="岗位"></el-table-column>
                <el-table-column prop="Edate" label="入职日期"></el-table-column>
                <el-table-column prop="Esource" label="人员来源"></el-table-column>
                <el-table-column prop="Edegree" label="最高学历"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit(scope.$index,scope.row)"
                        >编辑</el-button>
                        <!-- <el-button
                            type="text"
                            icon="el-icon-delete"
                            class="red"
                            disabled 
                            @click="handleDelete(scope.row)"
                        >删除</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="编号">
                    <el-input v-model="partsData.Eid "></el-input>
                </el-form-item>
				<el-form-item label="姓名">
                    <el-input v-model="partsData.Ename "></el-input>
                </el-form-item>
                <el-form-item label="性别">
                    <el-input v-model="partsData.Egender "></el-input>
                </el-form-item>
                <el-form-item label="出生日期">
                <el-input v-model="partsData.Ebirth "></el-input>
                </el-form-item>
				<el-form-item label="电话">
                    <el-input v-model="partsData.Ephone"></el-input>
                </el-form-item>
                <el-form-item label="身份证号">
                    <el-input v-model="partsData.Eidcard "></el-input>
                </el-form-item>
                <el-form-item label="部门">
                    <el-input v-model="partsData.Edepartment "></el-input>
                </el-form-item>
                <el-form-item label="岗位">
                    <el-input v-model="partsData.Eposition "></el-input>
                </el-form-item>
                <el-form-item label="入职日期">
                    <el-input v-model="partsData.Edate "></el-input>
                </el-form-item>
                <el-form-item label="人员来源">
                    <el-input v-model="partsData.Esource "></el-input>
                </el-form-item>
                <el-form-item label="最高学历">
                    <el-input v-model="partsData.Edegree "></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>
      <!-- 添加弹出框 -->
      <el-dialog title="添加" :visible.sync="addVisible" width="50%">
       <el-form ref="form" :model="form" label-width="100px">
         <el-form-item label="编号">
          <el-input v-model=" tempemployeeData.Eid"></el-input>
         </el-form-item>
         <el-form-item label="姓名">
           <el-input v-model="tempemployeeData.Ename"></el-input>
         </el-form-item>
         <el-form-item label="性别">
           <el-input v-model="tempemployeeData.Egender"></el-input>
          </el-form-item>
          <el-form-item label="身份证号">
           <el-input v-model="tempemployeeData.Eidcard"></el-input>
          </el-form-item>
          <el-form-item label="电话">
          <el-input v-model="tempemployeeData.Ephone"></el-input>
          </el-form-item>
          <el-form-item label="出生日期">
           <el-input v-model="tempemployeeData.Ebirth"></el-input>
          </el-form-item>
          <el-form-item label="部门">
           <el-input v-model="tempemployeeData.Edepartment"></el-input>
          </el-form-item>
          <el-form-item label="岗位">
           <el-input v-model="tempemployeeData.Eposition"></el-input>
          </el-form-item>
           <el-form-item label="入职日期">
             <el-input v-model="tempemployeeData.Edate "></el-input>
         </el-form-item>
          <el-form-item label="员工来源">
           <el-input v-model="tempemployeeData.Esource"></el-input>
          </el-form-item>
          <el-form-item label="最高学历">
           <el-input v-model="tempemployeeData.Edegree"></el-input>
          </el-form-item>
       </el-form>
       <span slot="footer" class="dialog-footer">
               <el-button @click="addVisible = false">取 消</el-button>
               <el-button type="primary" @click="Addconsumer">确 定</el-button>
           </span>
     </el-dialog>
    </div>
</template>

<script>
import { fetchemployeeData,fetchaddemployee,fetchupdateemployee,employeedelete, searchemployee} from '../../api/index';
export default {
    name: 'basetable',
    data() {
        return {
            employeeData: [],
            tempemployeeData:{},
            multipleSelection: [],
            employeedelete:{},
            partsData: {},
            delList: [],
            query: {}, 
            editVisible: false,
            addVisible:false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1
        };
    },
    created() {
        this.getemployeeData();
    },
    methods: {
     getemployeeData() {
        fetchemployeeData().then(res =>{
          this.employeeData=res.data.value
        })
      },
      // 触发搜索按钮
        handleSearch() {
            console.info(this.query)
            searchemployee(this.query).then(res => {
                console.info(res)
                if(res.code == 30001)
                {
                  this.getemployeeData();
                }
                else{
                this.employeeData=res.data.value
                }

            })
        },
      //删除操作
      handleDelete(row) {
        this.employeedelete = row
        employeedelete(this.employeedelete).then(res=>{console.info(res)
          console.log(this.employeedelete)
          console.log(res)
         window.location.reload()
        })
      },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.partsData = row;
            this.editVisible = true;
        },
        // 保存编辑
      saveEdit() {
        this.editVisible = false;
        this.$message.success(`修改第 ${this.idx + 1} 行成功`);
        fetchupdateemployee(this.partsData).then(res =>{console.info(res)
          console.log(this.partsData)
          console.log(res)
        })
      },
      //添加函数
      handleAddConsumer(){
        this.addVisible = true;
      },
      Addconsumer() {
        this.addVisible = false;
        this.$message.success(`添加成功`);
        fetchaddemployee(this.tempemployeeData).then(res =>{console.info(res)
          console.log(this.tempemployeeData)
          console.log(res)
          window.location.reload()
        })
      },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

/*.handle-select {*/
/*    width: 120px;*/
/*}*/

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
</style>
